﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;
using DataContracts;

namespace TrainingWorkshop.MVPWebsite.Authority.Views
{
    public class CreateNewAuthorityPresenter : Presenter<ICreateNewAuthorityView>
    {
        /// <summary>
        /// Authority Controller
        /// </summary>
        private IAuthorityController _controller;
        public CreateNewAuthorityPresenter([CreateNew] IAuthorityController controller)
        {
            _controller = controller;
        }

        /// <summary>
        /// Add a New Authority
        /// </summary>
        /// <returns></returns>
        public void AddNewAuthority()
        {
            bool result = false;
            DataContracts.AuthorityDTO authorityDTO = new AuthorityDTO();
            authorityDTO.AuthorityName = View.AuthorityName;
            DataContracts.AuthorityLevelDTO levelDTO = new AuthorityLevelDTO();
            levelDTO.LevelId = View.LevelId;
            levelDTO.LevelName = View.LevelName;
            authorityDTO.Level = levelDTO;
            result = _controller.AddNewAuthority(authorityDTO);
            if (result == true)
            {
                View.Redirect("AuthorityList.aspx");
            }
        }

        /// <summary>
        /// Get All Authority Level
        /// </summary>
        /// <returns></returns>
        public void GetAllAuthorityLevel()
        {
            View.AuthorityLevelList = _controller.GetAllAuthorityLevel();
        }

        public override void OnViewLoaded()
        {
            // TODO: Implement code that will be executed every time the view loads

        }

        public override void OnViewInitialized()
        {
            GetAllAuthorityLevel();
        }
    }
}




